//
//  MPCWebImageHeader.h
//  Pods
//
//  Created by jiaxuzhou on 2017/7/26.
//
//

#ifndef MPCWebImageHeader_h
#define MPCWebImageHeader_h

#import <pthread.h>

/// 切换SDWebImage 和 YYImage开关
#define MPT_USE_SDWebImageSwitch  0

#if MPT_USE_SDWebImageSwitch

#import "SDWebImageManager.h"
#import "UIView+WebCacheOperation.h"
#import "SDWebImageCompat.h"
#import "SDWebImageDownloader.h"

#else

#import <YYWebImage/YYWebImageManager.h>
#import <YYWebImage/YYWebImageOperation.h>
//#import <YYWebImage/_YYWebImageSetter.h>
#import <YYWebImage/YYImageCache.h>
#import <YYCache/YYDiskCache.h>
#import <YYCache/YYMemoryCache.h>

#endif




#define mp_dispatch_main_sync_safe(block)\
if (pthread_main_np()) {\
block();\
} else {\
dispatch_sync(dispatch_get_main_queue(), block);\
}

/// 淡入淡出动画
#define MPWebImageFadeAnimationKey @"MPWebImageFadeAnimationKey"

/// 图片缓存中的位置
typedef enum : NSUInteger
{
    MPWebImageCacheFromType_None,
    MPWebImageFromType_Memory,
    MPWebImageFromType_Disk,
} MPWebImageFromType;

/// 图片下载后的状态

typedef enum : NSUInteger {
    MPWebImageStage_Progress,
    MPWebImageStage_Cancelled,
    MPWebImageStage_Finished,
} MPWebImageStage;

/// The options to control image operation.
typedef NS_OPTIONS(NSUInteger, MPWebImageOptions) {
    
    /// Show network activity on status bar when download image.
    MPWebImageOption_ShowNetworkActivity = 1 << 0,
    
    /// Display progressive/interlaced/baseline image during download (same as web browser).
    MPWebImageOption_Progressive = 1 << 1,
    
    /// Display blurred progressive JPEG or interlaced PNG image during download.
    /// This will ignore baseline image for better user experience.
    MPWebImageOption_ProgressiveBlur = 1 << 2,
    
    /// Use NSURLCache instead of YYImageCache.
    MPWebImageOption_UseNSURLCache = 1 << 3,
    
    /// Allows untrusted SSL ceriticates.
    MPWebImageOption_AllowInvalidSSLCertificates = 1 << 4,
    
    /// Allows background task to download image when app is in background.
    MPWebImageOption_AllowBackgroundTask = 1 << 5,
    
    /// Handles cookies stored in NSHTTPCookieStore.
    MPWebImageOption_HandleCookies = 1 << 6,
    
    /// Load the image from remote and refresh the image cache.
    MPWebImageOption_RefreshImageCache = 1 << 7,
    
    /// Do not load image from/to disk cache.
    MPWebImageOption_IgnoreDiskCache = 1 << 8,
    
    /// Do not change the view's image before set a new URL to it.
    MPWebImageOption_IgnorePlaceHolder = 1 << 9,
    
    /// Ignore image decoding.
    /// This may used for image downloading without display.
    MPWebImageOption_IgnoreImageDecoding = 1 << 10,
    
    /// Ignore multi-frame image decoding.
    /// This will handle the GIF/APNG/WebP/ICO image as single frame image.
    MPWebImageOption_IgnoreAnimatedImage = 1 << 11,
    
    /// Set the image to view with a fade animation.
    /// This will add a "fade" animation on image view's layer for better user experience.
    MPWebImageOption_SetImageWithFadeAnimation = 1 << 12,
    
    /// Do not set the image to the view when image fetch complete.
    /// You may set the image manually.
    MPWebImageOption_AvoidSetImage = 1 << 13,
    
    /// This flag will add the URL to a blacklist (in memory) when the URL fail to be downloaded,
    /// so the library won't keep trying.
    MPWebImageOption_IgnoreFailedURL = 1 << 14,
};

typedef void (^MPWebImageSuccessBlock)(UIImage * _Nullable image,
NSURL * _Nullable url,
MPWebImageFromType from,
MPWebImageStage stage);

typedef void (^MPWebImageFailBlock)(
NSURL * _Nullable url,
MPWebImageFromType from,
MPWebImageStage stage,
NSError * _Nullable error);

typedef void(^MPWebImageDownloaderProgressBlock)(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL);


#endif /* MPCWebImageHeader_h */
